package cn.wolfcode.trip.admin.Controller;

import cn.wolfcode.trip.base.domain.SystemNotification;
import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.query.TravelCommendQuery;
import cn.wolfcode.trip.base.service.ISystemNotificationService;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.UploadUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * 推荐游记资源控制器
 */
@Controller
@RequestMapping("/travelCommend")
public class TravelCommendController {

    @Autowired
    private ITravelCommendService travelCommendService;
    @Autowired
    private ISystemNotificationService systemNotificationService;

    /**
     * 查出所有推荐游记
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String query(@ModelAttribute("qo") TravelCommendQuery qo, Model model){

       PageInfo<TravelCommend> pageInfo= travelCommendService.query(qo);
       model.addAttribute("pageInfo",pageInfo);

        return "/travelCommend/list";
    }

    /**
     * 保存修改推荐游记
     * @param travelCommend
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(TravelCommend travelCommend,SystemNotification systemNotification){
        JSONResult jsonResult =new JSONResult() ;
        travelCommendService.saveOrUpdate(travelCommend);

        systemNotificationService.saveOrUpdate(systemNotification);
        return jsonResult;
    }

}
